#pragma once
//General Purpose Register

template<size_t S>
class Formatter
{
public:
	Formatter(char const* format, ...)
	{
		va_list arglist;
		va_start(arglist, format);
		_vsnprintf_s_l(m_buff, S, S-1, format, NULL, arglist);
	}

	Formatter()
	{
		memset(m_buff,0,S);
	}

	void Format(char const* format, ...)
	{
		va_list arglist;
		va_start(arglist, format);
		_vsnprintf_s_l(m_buff, S, S-1, format, NULL, arglist);
	}

	operator char const*()
	{
		return m_buff;
	}

private:
	char m_buff[S];
};
typedef Formatter<4096> FT;

class Log
{
public:
	static void Debug(char const* msg);
	static void Info(char const* msg);
	static void Warn(char const* msg);
	static void Error(char const* msg);
};


class Encryption
{
public:
	static char const* Encrypt(char const* msg, char* buff, int buffLen)
	{
		char const* maxBuffPos = buff + (buffLen - 2);
		char const* pMsg = msg;
		char* pBuff = buff;
		for (; *pMsg!=0 && pBuff<maxBuffPos; ++pMsg,pBuff+=2)
		{
			Char2Other(*pMsg,pBuff);
		}
		*pBuff = 0;
		return buff;
	}
private:
	static void Char2Other(unsigned char c,char* out)
	{
		static char s_dic[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		out[0] = s_dic[c / 31];
		out[1] = s_dic[c % 31];
	}
};

class Profile
{
	friend Profile& theProfile();
public:
	Profile();
	string GetPrivateProfile(char const* appName, char const* keyName, char const* defaultValue);
	int GetPrivateProfile(char const* appName, char const* keyName, int defaultValue);
	void WritePrivateProfile(char const* appName, char const* keyName, char const* value);
	void WritePrivateProfile(char const* appName, char const*keyName, int value);
private:
	string m_fileName;
};

class StringSplit
{
public:
	int GetByDelimiter(char* originalStr, char const* delimit, vector<string>& destVector);

	friend StringSplit& theStringSplit();
};
